/**********************************************************************************************************************
 *  -------------------------------------------------------------------------------------------------------------------
 *  file description
 *  -------------------------------------------------------------------------------------------------------------------
 *         \file  export.c
 *         \unit  vkern
 *        \brief  The export command executes the function and specifies the section
 *      \details  v1.0.0
 *********************************************************************************************************************/
#include "export.h"
#include <stdio.h>
#include "vkern.h"

#if defined (KERN_USING_EXPORT) && !defined (KERN_EXPORT_NOT_SUSPORT)
/* initializer section */
static void init_nop_process(void) {}
SECTION("init.0") const init_item init_item_start = {init_nop_process};
SECTION("init.1") const init_item init_item1_level = {init_nop_process};
SECTION("init.2") const init_item init_item_end= {init_nop_process};

/* task register section */
static int task_nop_process(void* data) { return 0; }
SECTION("task.0") const task_item task_item_start = {0, 0, 0, task_nop_process};
SECTION("task.1") const task_item task_item1_level = {0, 0, 0, task_nop_process};
SECTION("task.2") const task_item task_item_end = {0, 0, 0, task_nop_process};

/** initializer execute.
 *  \param[in] none.
 *  \return none
 */
void init_execute(void)
{
    const init_item *it = &init_item_start + 1;
    init_handler_t handler = NULL;
    while (it < &init_item_end) {
        handler = it++->handler;
        if (handler != NULL) handler();
    }
}

/** task register execute.
 *  \param[in] none.
 *  \return none
 */
void task_execute(void)
{
    const task_item *it = &task_item_start + 1;
    while (it < &task_item_end) {
        if (it->handler != task_nop_process)
        {
            if (it->task == 0)
            {
                vtask_create_dynamic(it->prio, VTASK_STATE_WAIT, it->period, it->handler);
            }
            else  
            {
                vtask_create(it->task, it->prio, VTASK_STATE_WAIT, it->period, it->handler);
            }
        }
        it++;
    }
}
#else 
void init_execute(void)
{

}

void task_execute(void)
{

}

#endif 
